<?php

namespace hiduoke\services\formBuilder\form;

use FormBuilder\Driver\FormComponent;
use FormBuilder\Factory\Elm;
use FormBuilder\Util;

class DkObject extends FormComponent
{
    public function __construct($field, $title, $value = [])
    {
        parent::__construct($field, $title, $value);
        $this->setRuleType('object');
    }

    public function createValidate()
    {
        return Elm::validateStr();
    }

    /**
     * @param array $rules
     * @return array
     */
    protected function tidyRule(array $rules)
    {
        foreach ($rules as $k => $rule) {
            if (Util::isComponent($rule)) {
                $rules[$k] = $rule->build();
            }
        }
        return $rules;
    }

    public function rule(array $rules)
    {
        $this->props['rule'] = $this->tidyRule($rules);
        return $this;
    }
}
